package com.p2p.controller.vipManagement;

import cn.hutool.core.bean.BeanUtil;
import com.p2p.common.DTO.BorrowerSelectDTO;
import com.p2p.common.R;
import com.p2p.common.base.RespResult;
import com.p2p.common.view.BorrowerVo;
import com.p2p.entity.Borrower;
import com.p2p.service.vipManagementService.BorrowerService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("/borrower")
@Api(value = "借贷用户API",tags = "会员管理中借贷用户API")
public class BorrowerController {

    @Autowired
    private BorrowerService borrowerService;

    /**
     * 添加借贷用户
     * @return R
     */
    @PostMapping("/addBorrower")
    @ApiOperation(value = "添加借贷用户",notes = "添加借贷用户",httpMethod = "POST", response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message="成功"),
            @ApiResponse(code=400,message="代表参数格式不对"),
            @ApiResponse(code=404,message="代表找不到此请求"),
            @ApiResponse(code=500,message="代表后端代码出现异常"),
    })
    @ResponseBody
    public RespResult addBorrower(@RequestBody @ApiParam(name = "borrower",value = "借贷用户实体VO",required = true) BorrowerVo borrowerVo){
        Borrower borrower = BeanUtil.copyProperties(borrowerVo, Borrower.class);
        return borrowerService.addBorrower(borrower);
    }


    /**
     * 分页显示所有借贷用户
     * @param currentPage 当前页码数默认第一页
     * @param pageSize 每页显示记录数
     * @return R
     */
    @ApiOperation(value = "分页显示所有借贷用户",notes = "分页显示所有借贷用户",
            httpMethod = "GET", response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "currentPage",value = "当前页码数默认第一页",paramType = "query",dataType = "String",required = false),
            @ApiImplicitParam(name = "pageSize",value = "每页显示记录数",paramType = "query",dataType = "String",required = false)
    })
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @GetMapping(value = "/findBorrowerList")
    @ResponseBody
    public RespResult findBorrowerList(Integer currentPage,Integer pageSize ){
        return borrowerService.findBorrowerList(currentPage,pageSize);
    }



    /**
     * 修改借贷用户信息
     * @return R
     */
    @ApiOperation(value = "修改借贷用户信息",notes = "修改借贷用户信息",
            httpMethod = "POST", response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @PostMapping(value = "/updateBorrower")
    @ResponseBody
    public RespResult updateBorrower(@RequestBody @ApiParam(name = "borrowerVo",value = "借贷用户实体Vo",required = true) BorrowerVo borrowerVo){
        Borrower borrower = BeanUtil.copyProperties(borrowerVo, Borrower.class);
        return borrowerService.updateBorrower(borrower);
    }

    /**
     * 根据id回显借贷用户信息
     * @return R
     */
    @ApiOperation(value = "根据id回显借贷用户信息",notes = "根据id回显借贷用户信息",
            httpMethod = "GET", response = R.class)
    @ApiImplicitParam(name = "id",value = "借贷用户id",paramType = "query",dataType = "String",required = true)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @GetMapping(value = "/findBorrowerById")
    @ResponseBody
    public RespResult findBorrowerById(Long id){
        return borrowerService.findBorrowerById(id);
    }


    /**
     * 根据id修改借贷用户密码
     * @return R
     */
    @ApiOperation(value = "根据id修改借贷用户密码",notes = "根据id修改借贷用户密码",
            httpMethod = "POST", response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "借贷用户id",paramType = "query",dataType = "String",required = true),
            @ApiImplicitParam(name = "loginPwd",value = "登录密码",paramType = "query",dataType = "String",required = false),
            @ApiImplicitParam(name = "payPwd",value = "支付密码",paramType = "query",dataType = "String",required = false)
    })
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @PostMapping (value = "/updateBorrowerPwdById")
    @ResponseBody
    public RespResult updateBorrowerPwdById(Long id,String loginPwd,String payPwd){
        return borrowerService.updateBorrowerPwdById(id,loginPwd,payPwd);
    }



    /**
     * 更据条件查询分页显示所有借贷用户
     * @return R
     */
    @ApiOperation(value = "更据条件查询分页显示所有借贷用户",notes = "更据条件查询分页显示所有借贷用户",
            httpMethod = "GET", response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "currentPage",value = "当前页码数默认第一页",paramType = "query",dataType = "String",required = true),
            @ApiImplicitParam(name = "pageSize",value = "每页显示记录数",paramType = "query",dataType = "String",required = true),
            @ApiImplicitParam(name = "condition",value = "条件",paramType = "query",dataType = "String",required = true)
    })
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @GetMapping(value = "/findBorrowerByCondition")
    @ResponseBody
    public RespResult findBorrowerByCondition(@RequestBody @ApiParam(name = "borrowerSelectDTO",value = "借贷用户查询实体DTO",required = true) BorrowerSelectDTO borrowerSelectDTO ){
        return borrowerService.findBorrowerByCondition(borrowerSelectDTO);
    }




    /**
     * 根据id删除借贷用户信息
     * @return R
     */
    @ApiOperation(value = "根据id删除借贷用户信息",notes = "根据id删除借贷用户信息",
            httpMethod = "POST", response = R.class)
    @ApiImplicitParam(name = "id",value = "借贷用户id",paramType = "query",dataType = "String",required = true)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @PostMapping (value = "/delBorrowerById")
    @ResponseBody
    public RespResult delBorrowerById(Long id){
        return borrowerService.delBorrowerById(id);
    }



}
